package com.zzty.txj.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import com.zzty.txj.entity.Count;
import com.zzty.txj.entity.Count1;
import com.zzty.txj.entity.ExcelData;
import com.zzty.txj.entity.ExcelInfo;

import com.zzty.txj.util.ExcelUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.ss.usermodel.CellStyle;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/excel")
public class ExcelController {
    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(DpostController.class);
    @RequestMapping(value = "/export111",method = RequestMethod.POST)//原来是POST
    public void excel(HttpServletResponse response,@RequestParam("i1") String startDate[],
    @RequestParam("i2") String finishDate[],@RequestParam("i3") String name[],
                      @RequestParam("i4") String subject[],@RequestParam("i5") Integer finishTimes[]
    ) throws Exception {


        ExcelData data = new ExcelData();
        data.setName("打卡记录");
        //添加表头
        List<String> titles = new ArrayList();

            titles.add("起止日期");
            titles.add("终止日期");
            titles.add("姓名");
            titles.add("科目");
            titles.add("完成次数");
        data.setTitles(titles);
        //添加列
        List<List<Object>> rows = new ArrayList();
        List<Object> row = null;
            for(int j=0;j<startDate.length;j++){
                row=new ArrayList();
                row.add(startDate[j]);
                row.add(finishDate[j]);
                row.add(name[j]);
                row.add(subject[j]);
                row.add(finishTimes[j]);
                rows.add(row);
            }
        data.setRows(rows);
            logger.info("excel"+rows.toString());
        SimpleDateFormat fdate=new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
        String fileName=fdate.format(new Date())+".xls";
        ExcelUtils.exportExcel(response, fileName, data);
    }
}

